unit GL_BALANCE;


interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TGLBALANCE=class(TUniEngine)
  private
    FACCOUNTID: string;
    FSUMID    : string;
    FCREATEDATE: string;
    FCREATEUSER: string;
    FLATESTOPDATE: string;
    FLATESTOPUSER: string;
    FSETYEAR  : Extended;
    FSETMONTH : Extended;
    FAVIMONEY : Extended;
    FUSEMONEY : Extended;
    FMINUSMONEY: Extended;
    FAVINGMONEY: Extended;
    FLASTVER  : string;
    FFROMCTRLID: string;
    FREMARK   : string;
    FBALVERSION: Extended;
    FRCID     : Extended;
    FCCID     : Extended;
    FRGCODE   : string;
    FBALANCEID: Extended;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
    function  GetNextMAXX(AUniConnection:TUniConnection):Extended;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property ACCOUNTID: string read FACCOUNTID write FACCOUNTID;
    property SUMID    : string read FSUMID     write FSUMID;
    property CREATEDATE: string read FCREATEDATE write FCREATEDATE;
    property CREATEUSER: string read FCREATEUSER write FCREATEUSER;
    property LATESTOPDATE: string read FLATESTOPDATE write FLATESTOPDATE;
    property LATESTOPUSER: string read FLATESTOPUSER write FLATESTOPUSER;
    property SETYEAR  : Extended read FSETYEAR   write FSETYEAR;
    property SETMONTH : Extended read FSETMONTH  write FSETMONTH;
    property AVIMONEY : Extended read FAVIMONEY  write FAVIMONEY;
    property USEMONEY : Extended read FUSEMONEY  write FUSEMONEY;
    property MINUSMONEY: Extended read FMINUSMONEY write FMINUSMONEY;
    property AVINGMONEY: Extended read FAVINGMONEY write FAVINGMONEY;
    property LASTVER  : string read FLASTVER   write FLASTVER;
    property FROMCTRLID: string read FFROMCTRLID write FFROMCTRLID;
    property REMARK   : string read FREMARK    write FREMARK;
    property BALVERSION: Extended read FBALVERSION write FBALVERSION;
    property RCID     : Extended read FRCID      write FRCID;
    property CCID     : Extended read FCCID      write FCCID;
    property RGCODE   : string read FRGCODE    write FRGCODE;
    property BALANCEID: Extended read FBALANCEID write FBALANCEID;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AGLBALANCE:TGLBALANCE):TGLBALANCE;overload;        
    class procedure CopyIt(AGLBALANCE:TGLBALANCE;var Result:TGLBALANCE);overload;       
  end;

implementation

{ TGLBALANCE }
procedure TGLBALANCE.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('ACCOUNT_ID').Value := ACCOUNTID;
        ParamByName('SUM_ID').Value := SUMID;
        ParamByName('CREATE_DATE').Value := CREATEDATE;
        ParamByName('CREATE_USER').Value := CREATEUSER;
        ParamByName('LATEST_OP_DATE').Value := LATESTOPDATE;
        ParamByName('LATEST_OP_USER').Value := LATESTOPUSER;
        ParamByName('SET_YEAR').Value := SETYEAR;
        ParamByName('SET_MONTH').Value := SETMONTH;
        ParamByName('AVI_MONEY').Value := AVIMONEY;
        ParamByName('USE_MONEY').Value := USEMONEY;
        ParamByName('MINUS_MONEY').Value := MINUSMONEY;
        ParamByName('AVING_MONEY').Value := AVINGMONEY;
        ParamByName('LAST_VER').Value := LASTVER;
        ParamByName('FROMCTRLID').Value := FROMCTRLID;
        ParamByName('REMARK').Value := REMARK;
        ParamByName('BAL_VERSION').Value := BALVERSION;
        ParamByName('RCID').Value := RCID;
        ParamByName('CCID').Value := CCID;
        ParamByName('RG_CODE').Value := RGCODE;
        ParamByName('BALANCE_ID').Value := BALANCEID; 
      end;
      otEdit:
      begin
        ParamByName('ACCOUNT_ID').Value := ACCOUNTID;
        ParamByName('SUM_ID').Value := SUMID;
        ParamByName('CREATE_DATE').Value := CREATEDATE;
        ParamByName('CREATE_USER').Value := CREATEUSER;
        ParamByName('LATEST_OP_DATE').Value := LATESTOPDATE;
        ParamByName('LATEST_OP_USER').Value := LATESTOPUSER;
        ParamByName('SET_YEAR').Value := SETYEAR;
        ParamByName('SET_MONTH').Value := SETMONTH;
        ParamByName('AVI_MONEY').Value := AVIMONEY;
        ParamByName('USE_MONEY').Value := USEMONEY;
        ParamByName('MINUS_MONEY').Value := MINUSMONEY;
        ParamByName('AVING_MONEY').Value := AVINGMONEY;
        ParamByName('LAST_VER').Value := LASTVER;
        ParamByName('FROMCTRLID').Value := FROMCTRLID;
        ParamByName('REMARK').Value := REMARK;
        ParamByName('BAL_VERSION').Value := BALVERSION;
        ParamByName('RCID').Value := RCID;
        ParamByName('CCID').Value := CCID;
        ParamByName('RG_CODE').Value := RGCODE;
        ParamByName('BALANCE_ID').Value := BALANCEID; 
      end;  
      otDelt:
      begin
        ParamByName('BALANCE_ID').Value := BALANCEID; 
      end;  
    end;
  end;
end;

function TGLBALANCE.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('GL_BALANCE',['BALANCE_ID',BALANCEID],AUniConnection);
end;

function TGLBALANCE.GetNextIdex: Integer;
begin

end;

function TGLBALANCE.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TGLBALANCE.GetStrDelete: string;
begin
  Result:='DELETE FROM GL_BALANCE WHERE   BALANCE_ID=:BALANCE_ID';
end;

function TGLBALANCE.GetStrInsert: string;
begin
  Result:='INSERT INTO GL_BALANCE'
         +'    ( ACCOUNT_ID, SUM_ID, CREATE_DATE, CREATE_USER, LATEST_OP_DATE'
         +'    , LATEST_OP_USER, SET_YEAR, SET_MONTH, AVI_MONEY, USE_MONEY'
         +'    , MINUS_MONEY, AVING_MONEY, LAST_VER, FROMCTRLID, REMARK'
         +'    , BAL_VERSION, RCID, CCID, RG_CODE, BALANCE_ID)'
         +'    VALUES'
         +'    (:ACCOUNT_ID,:SUM_ID,:CREATE_DATE,:CREATE_USER,:LATEST_OP_DATE'
         +'    ,:LATEST_OP_USER,:SET_YEAR,:SET_MONTH,:AVI_MONEY,:USE_MONEY'
         +'    ,:MINUS_MONEY,:AVING_MONEY,:LAST_VER,:FROMCTRLID,:REMARK'
         +'    ,:BAL_VERSION,:RCID,:CCID,:RG_CODE,:BALANCE_ID)';
end;

function TGLBALANCE.GetStrsIndex: string;
begin
  Result:=Format('%F',[BALANCEID]);
end;

function TGLBALANCE.GetStrUpdate: string;
begin
  Result:='UPDATE  GL_BALANCE SET'
         +'    ACCOUNT_ID=:ACCOUNT_ID,'
         +'    SUM_ID=:SUM_ID,'
         +'    CREATE_DATE=:CREATE_DATE,'
         +'    CREATE_USER=:CREATE_USER,'
         +'    LATEST_OP_DATE=:LATEST_OP_DATE,'
         +'    LATEST_OP_USER=:LATEST_OP_USER,'
         +'    SET_YEAR=:SET_YEAR,'
         +'    SET_MONTH=:SET_MONTH,'
         +'    AVI_MONEY=:AVI_MONEY,'
         +'    USE_MONEY=:USE_MONEY,'
         +'    MINUS_MONEY=:MINUS_MONEY,'
         +'    AVING_MONEY=:AVING_MONEY,'
         +'    LAST_VER=:LAST_VER,'
         +'    FROMCTRLID=:FROMCTRLID,'
         +'    REMARK=:REMARK,'
         +'    BAL_VERSION=:BAL_VERSION,'
         +'    RCID=:RCID,'
         +'    CCID=:CCID,'
         +'    RG_CODE=:RG_CODE'
         +'    WHERE BALANCE_ID=:BALANCE_ID';
end;

constructor TGLBALANCE.Create;
begin

end;

destructor TGLBALANCE.Destroy;
begin

  inherited;
end;

class function TGLBALANCE.ReadDS(AUniQuery: TUniQuery): TUniEngine;
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  Result:=TGLBALANCE.Create;

  with TGLBALANCE(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='ACCOUNT_ID' then
      begin
        ACCOUNTID:=Field.AsString;
      end else
      if FieldName='SUM_ID' then
      begin
        SUMID    :=Field.AsString;
      end else
      if FieldName='CREATE_DATE' then
      begin
        CREATEDATE:=Field.AsString;
      end else
      if FieldName='CREATE_USER' then
      begin
        CREATEUSER:=Field.AsString;
      end else
      if FieldName='LATEST_OP_DATE' then
      begin
        LATESTOPDATE:=Field.AsString;
      end else
      if FieldName='LATEST_OP_USER' then
      begin
        LATESTOPUSER:=Field.AsString;
      end else
      if FieldName='SET_YEAR' then
      begin
        SETYEAR  :=Field.AsFloat;
      end else
      if FieldName='SET_MONTH' then
      begin
        SETMONTH :=Field.AsFloat;
      end else
      if FieldName='AVI_MONEY' then
      begin
        AVIMONEY :=Field.AsFloat;
      end else
      if FieldName='USE_MONEY' then
      begin
        USEMONEY :=Field.AsFloat;
      end else
      if FieldName='MINUS_MONEY' then
      begin
        MINUSMONEY:=Field.AsFloat;
      end else
      if FieldName='AVING_MONEY' then
      begin
        AVINGMONEY:=Field.AsFloat;
      end else
      if FieldName='LAST_VER' then
      begin
        LASTVER  :=Field.AsString;
      end else
      if FieldName='FROMCTRLID' then
      begin
        FROMCTRLID:=Field.AsString;
      end else
      if FieldName='REMARK' then
      begin
        REMARK   :=Field.AsString;
      end else
      if FieldName='BAL_VERSION' then
      begin
        BALVERSION:=Field.AsFloat;
      end else
      if FieldName='RCID' then
      begin
        RCID     :=Field.AsFloat;
      end else
      if FieldName='CCID' then
      begin
        CCID     :=Field.AsFloat;
      end else
      if FieldName='RG_CODE' then
      begin
        RGCODE   :=Field.AsString;
      end else
      if FieldName='BALANCE_ID' then
      begin
        BALANCEID:=Field.AsFloat;
      end;
    end
  end;  
end;

class procedure TGLBALANCE.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  if Result=nil then Exit;

  with TGLBALANCE(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='ACCOUNT_ID' then
      begin
        ACCOUNTID:=Field.AsString;
      end else
      if FieldName='SUM_ID' then
      begin
        SUMID    :=Field.AsString;
      end else
      if FieldName='CREATE_DATE' then
      begin
        CREATEDATE:=Field.AsString;
      end else
      if FieldName='CREATE_USER' then
      begin
        CREATEUSER:=Field.AsString;
      end else
      if FieldName='LATEST_OP_DATE' then
      begin
        LATESTOPDATE:=Field.AsString;
      end else
      if FieldName='LATEST_OP_USER' then
      begin
        LATESTOPUSER:=Field.AsString;
      end else
      if FieldName='SET_YEAR' then
      begin
        SETYEAR  :=Field.AsFloat;
      end else
      if FieldName='SET_MONTH' then
      begin
        SETMONTH :=Field.AsFloat;
      end else
      if FieldName='AVI_MONEY' then
      begin
        AVIMONEY :=Field.AsFloat;
      end else
      if FieldName='USE_MONEY' then
      begin
        USEMONEY :=Field.AsFloat;
      end else
      if FieldName='MINUS_MONEY' then
      begin
        MINUSMONEY:=Field.AsFloat;
      end else
      if FieldName='AVING_MONEY' then
      begin
        AVINGMONEY:=Field.AsFloat;
      end else
      if FieldName='LAST_VER' then
      begin
        LASTVER  :=Field.AsString;
      end else
      if FieldName='FROMCTRLID' then
      begin
        FROMCTRLID:=Field.AsString;
      end else
      if FieldName='REMARK' then
      begin
        REMARK   :=Field.AsString;
      end else
      if FieldName='BAL_VERSION' then
      begin
        BALVERSION:=Field.AsFloat;
      end else
      if FieldName='RCID' then
      begin
        RCID     :=Field.AsFloat;
      end else
      if FieldName='CCID' then
      begin
        CCID     :=Field.AsFloat;
      end else
      if FieldName='RG_CODE' then
      begin
        RGCODE   :=Field.AsString;
      end else
      if FieldName='BALANCE_ID' then
      begin
        BALANCEID:=Field.AsFloat;
      end;
    end
  end;  
end;

class function  TGLBALANCE.CopyIt(AGLBALANCE: TGLBALANCE): TGLBALANCE;
begin
  Result:=TGLBALANCE.Create;
  TGLBALANCE.CopyIt(AGLBALANCE,Result)
end;

class procedure TGLBALANCE.CopyIt(AGLBALANCE:TGLBALANCE;var Result:TGLBALANCE);
begin
  if Result=nil then Exit;
  Result.ACCOUNTID:=AGLBALANCE.ACCOUNTID;
  Result.SUMID    :=AGLBALANCE.SUMID;
  Result.CREATEDATE:=AGLBALANCE.CREATEDATE;
  Result.CREATEUSER:=AGLBALANCE.CREATEUSER;
  Result.LATESTOPDATE:=AGLBALANCE.LATESTOPDATE;
  Result.LATESTOPUSER:=AGLBALANCE.LATESTOPUSER;
  Result.SETYEAR  :=AGLBALANCE.SETYEAR;
  Result.SETMONTH :=AGLBALANCE.SETMONTH;
  Result.AVIMONEY :=AGLBALANCE.AVIMONEY;
  Result.USEMONEY :=AGLBALANCE.USEMONEY;
  Result.MINUSMONEY:=AGLBALANCE.MINUSMONEY;
  Result.AVINGMONEY:=AGLBALANCE.AVINGMONEY;
  Result.LASTVER  :=AGLBALANCE.LASTVER;
  Result.FROMCTRLID:=AGLBALANCE.FROMCTRLID;
  Result.REMARK   :=AGLBALANCE.REMARK;
  Result.BALVERSION:=AGLBALANCE.BALVERSION;
  Result.RCID     :=AGLBALANCE.RCID;
  Result.CCID     :=AGLBALANCE.CCID;
  Result.RGCODE   :=AGLBALANCE.RGCODE;
  Result.BALANCEID:=AGLBALANCE.BALANCEID;
end;

function TGLBALANCE.GetNextMAXX(AUniConnection: TUniConnection): Extended;
var
  SQLA:string;
  TMPA:Integer;
begin
  SQLA:='SELECT MAX(BALANCE_ID)+20  AS VALUE FROM GL_BALANCE';
  Result:=CheckField(SQLA,'VALUE',AUniConnection);
  Result:=Trunc(Result / 10) * 10;
end;

end.

